<template>
  <view>

    <!-- 顶部自定义导航 -->
    <tn-nav-bar :isBack="false" :bottomShadow="false" backgroundColor="none">
      <view class="custom-nav tn-flex tn-flex-col-center tn-flex-row-center">
        <!-- 字 -->
        <view class="custom-nav__search tn-flex tn-flex-col-center tn-flex-row-center ">
          <view class="custom-nav__search__box tn-flex tn-flex-col-center tn-flex-row-center tn-color-black">
            <text class="tn-text-bold tn-text-xl">备忘</text>
          </view>
        </view>
      </view>
    </tn-nav-bar>

    <view class="" :style="{paddingTop: vuex_custom_bar_height + 'px'}">
      <scroll-view v-if="memoList.length > 0" :scroll-y="true" style="height: calc(100vh - 300rpx);">
        <view v-for="(item, index) in memoList" :key="index"
              @click="goToMemoDetail(item)" @longpress="deleteOne(item)">
          <view>

            <view class="tn-flex tn-flex-col-top tn-margin tn-cat-shadow tn-padding">
              <view class="">
                <view class="icon15__item--icon tn-flex tn-flex-row-center tn-flex-col-center tn-shadow-blur"
                      style="background-color: #F3F2F7;color: #7C8191;">
                  <view class="tn-icon-notice"></view>
                </view>
              </view>
              <view class="tn-padding-left-sm" style="width: 100%;">
                <view class="tn-flex tn-flex-row-between tn-flex-col-between">
                  <view class="justify-content-item">
                    <text class="tn-color-cat tn-text-lg tn-text-bold">{{item.title}}</text>
                  </view>
                </view>
                <view class=" tn-padding-top-xs  tn-text-ellipsis-2">
                  <text class="tn-color-gray">
                    {{item.content}}
                  </text>
                </view>
                <view class="tn-flex tn-flex-row-between tn-flex-col-between tn-margin-top-sm">
                  <view class="justify-content-item tn-round tn-text-xs tn-bg-orangered--light tn-color-orangered"
                        style="padding: 5rpx 15rpx;">
                    <text class="tn-padding-right-xs">#</text>
                    {{item.tag}}
                  </view>
                  <view class="justify-content-item tn-color-gray tn-text-center tn-color-gray">
                    <text class="tn-icon-time tn-padding-right-xs tn-text-df"></text>
                    <text class="tn-text-sm">{{item.dueTime}}</text>
                  </view>
                </view>
              </view>
            </view>
          </view>

        </view>
      </scroll-view>
    </view>

    <view>
      <!-- 提示窗示例 -->
      <uni-popup ref="alertDialog" type="dialog">
        <uni-popup-dialog type="error" cancelText="关闭" confirmText="删除" title="删除" :content="sureContent" @confirm="dialogConfirm"
        ></uni-popup-dialog>
      </uni-popup>
    </view>




    <view>
      <tn-popup v-model="showDetail" mode="bottom" borderRadius="16" length="700" closeBtn>
        <view class="tn-blogger-content showDetailMsg">{{showDetailMsg}}</view>
      </tn-popup>

    </view>


    <view>
      <tn-popup v-model="showAdd" mode="center" borderRadius="16" length="700" closeBtn>
        <view class="memo-common">添加备忘</view>
        <view class="">
          <uni-section title="输入标题" type="line">
            <view>
              <input type="text" placeholder="请输入谷子名称" v-model="data.title"/>
            </view>
          </uni-section>
        </view>

        <view class="grain-common">
          <uni-section title="输入备忘标签名称" type="line">
            <view>
              <input v-model="data.tag" placeholder="例如：学习"/>
            </view>
          </uni-section>
        </view>

        <view class="grain-common">
          <uni-section title="输入备忘内容" type="line">
            <view>
              <textarea v-model="data.content"/>
            </view>
          </uni-section>
        </view>

        <view class="grain-common" style="margin-bottom: 24rpx">
          <uni-section title="提醒时间" type="line">
            <view style="width: 50%">
              <uni-datetime-picker type="datetime" v-model="data.dueTime"/>
            </view>
          </uni-section>
        </view>

        <view class="grain-bottom">
          <button type="default" class="my-button" @click="addNewMemo">提交</button>
        </view>
      </tn-popup>

    </view>


    <text class="tn-icon-add  tn-color-bluepurple add-grain" @click="goToAddNew"></text>


    <view class="tabbar footerfixed">
      <view class="action navbar__item -blue" @click="switchToHome">
        <view class="bar-icon">
          <view class="tn-icon-home-capsule navbar__icon">
          </view>
        </view>
        <view class="-blue bar-text">
          <text style="margin-bottom:-100rpx;font-size:20rpx;color:#303030;">首页</text>
        </view>
      </view>
      <view class="action navbar__item -orange" @click="switchToGroup">
        <view class="bar-icon">
          <view class="tn-icon-honor navbar__icon">
          </view>
        </view>
        <view class="-orange bar-text">
          <text style="margin-bottom:-100rpx;font-size:20rpx;color:#303030;">分组</text>
        </view>
      </view>
      <view class="action navbar__item -yellow" @click="switchToMemo">
        <view class="bar-icon">
          <view class="tn-icon-discover-planet navbar__icon">
          </view>
        </view>
        <view class="-yellow bar-text">
          <text style="margin-bottom:-100rpx;font-size:20rpx;color:#303030;">备忘</text>
        </view>
      </view>
      <view class="action navbar__item -purple" @click="switchToMy">
        <view class="bar-icon">
          <view class="tn-icon-my navbar__icon">
            <!-- <tn-badge :absolute="true">99+</tn-badge> -->
          </view>
        </view>
        <view class="-purple bar-text">
          <text style="margin-bottom:-100rpx;font-size:20rpx;color:#303030;">我的</text>
        </view>
      </view>
    </view>
    <view class="tn-padding-xl"></view>

  </view>
</template>

<script>
import {addMemo, deleteOneMemo, memoList} from "@/api/memo";
import uniSection from "@/uni_modules/uni-section/components/uni-section/uni-section.vue";
import uniDatetimePicker
  from "@/uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue";

export default {
  components: {uniDatetimePicker, uniSection},
  data() {
    return {
      data: {
        title: '',
        content: '',
        tag: '',
        dueTime: ''
      },
      deleteId: '',
      sureContent: '',
      showDetail: false,
      showAdd: false,
      memoList: [],
      showDetailMsg: ''

    };

  },
  onLoad() {
    // #ifndef MP-WEIXIN
    uni.hideTabBar()
    // #endif
  },
  onShow() {
    memoList().then(res => {
      console.log(res)
      this.memoList = res.data
    })
  },

  methods: {
    addNewMemo() {
      console.log('新增备忘')
      console.log(this.data)
      if(this.checkData(this.data)){
        addMemo(this.data).then(res => {
          memoList().then(res => {
            this.memoList = res.data
          })
        })
        this.showAdd = false
      }


    },
    checkData(data){
      if(!data.title){
        uni.showToast({
          title: '请输入标题',
          icon: 'none'
        })
        return false
      }
      if(!data.content){
        uni.showToast({
          title: '请输入内容',
          icon: 'none'
        })
        return false
      }
      if(!data.tag){
        uni.showToast({
          title: '请输入标签',
          icon: 'none'
        })
        return false
      }
      if(!data.dueTime){
        uni.showToast({
          title: '请输入提醒时间',
          icon: 'none'
        })
        return false
      }
      return true
    },
    goToAddNew() {
      console.log('跳转到新增备忘')
      this.showAdd = true
    },
    goToMemoDetail(item) {
      console.log('跳转到备忘详情')
      this.showDetail=true
      this.showDetailMsg = item.content
    },

    dialogConfirm(){
      deleteOneMemo(this.deleteId).then(res => {
        memoList().then(res => {
          this.memoList = res.data
        })
      })
    },
    deleteOne(item) {
      console.log('删除备忘')
      this.deleteId = item.id
      this.sureContent = '确定删除【'+item.title+'】吗？'
      this.$refs.alertDialog.open(item)
    },


    switchToGroup() {
      console.log('切换到分组')
      uni.switchTab({
        url: '/pages/group/group'
      })
    },
    switchToHome() {
      console.log('切换到首页')
      uni.switchTab({
        url: '/pages/index/index'
      })
    },
    switchToMemo() {
      console.log('切换到备忘')
      uni.switchTab({
        url: '/pages/alarm/alarm'
      })
    },
    switchToMy() {
      console.log('切换到我的')
      uni.switchTab({
        url: '/pages/userInfo/userInfo'
      })
    },

  },
}
</script>


<style lang="scss" scoped>

.memo-common{
  height: 70rpx;
  //标题居中显示
  line-height: 70rpx;
  text-align: center;
  font-size: 30rpx;
}
.message {
  max-height: 100vh;
}

.showDetailMsg{
  margin-top: 100rpx;
  margin-left: 25rpx;
  font-size: 56rpx;
  line-height: 30rpx;
  text-align: justify;
}
/* 自定义导航栏内容 start */
.custom-nav {
  height: 100%;

  &__back {
    margin: auto 5rpx;
    font-size: 40rpx;
    margin-right: 10rpx;
    flex-basis: 5%;
    width: 100rpx;
    position: absolute;
  }
}

/* 自定义导航栏内容 end */

/* 底部安全边距 start*/
.tn-tabbar-height {
  min-height: 120rpx;
  height: calc(140rpx + env(safe-area-inset-bottom) / 2);
  height: calc(140rpx + constant(safe-area-inset-bottom));
}

.tn-message-fixed {
  position: fixed;
  background-color: rgba(255, 255, 255, 1);
  box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
  top: 0;
  width: 100%;
  transition: all 0.25s ease-out;
  z-index: 100;
}


/* 图标容器1 start */
.icon1 {
  &__item {
    width: 30%;
    background-color: #FFFFFF;
    border-radius: 10rpx;
    padding: 30rpx;
    margin: 20rpx 10rpx;
    transform: scale(1);
    transition: transform 0.3s linear;
    transform-origin: center center;

    &--icon {
      width: 90rpx;
      height: 90rpx;
      font-size: 60rpx;
      border-radius: 50%;
      margin-bottom: 18rpx;
      position: relative;
      z-index: 1;

      &::after {
        content: " ";
        position: absolute;
        z-index: -1;
        width: 100%;
        height: 100%;
        left: 0;
        bottom: 0;
        border-radius: inherit;
        opacity: 1;
        transform: scale(1, 1);
        background-size: 100% 100%;
        background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/icon_bg5.png);
      }
    }
  }
}

.tn-color-cat {
  color: #1D2541;
}

/* 页面阴影 start*/
.tn-cat-shadow {
  border-radius: 15rpx;
  box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
}


/* 标签*/
.tag {
  margin: 10rpx 0 10rpx 10rpx;
  color: #7C8191;
  background-color: #F3F2F7;
  padding: 4rpx 14rpx 6rpx;
  border-radius: 10rpx;
  font-size: 20rpx;
}

/* 图标容器15 start */
.icon15 {
  &__item {
    width: 30%;
    background-color: #FFFFFF;
    border-radius: 10rpx;
    padding: 30rpx;
    margin: 20rpx 10rpx;
    transform: scale(1);
    transition: transform 0.3s linear;
    transform-origin: center center;

    &--icon {
      width: 105rpx;
      height: 105rpx;
      font-size: 60rpx;
      border-radius: 50%;
      margin-bottom: 18rpx;
      position: relative;
      z-index: 1;

      &::after {
        content: " ";
        position: absolute;
        z-index: -1;
        width: 100%;
        height: 100%;
        left: 0;
        bottom: 0;
        border-radius: inherit;
        opacity: 1;
        transform: scale(1, 1);
        background-size: 100% 100%;


      }
    }
  }
}

/* 用户头像 start */
.logo-image {
  width: 100rpx;
  height: 100rpx;
  position: relative;
}

.logo-pic {
  background-size: cover;
  background-repeat: no-repeat;
  // background-attachment:fixed;
  background-position: top;
  border: 1rpx solid rgba(255, 255, 255, 0.05);
  box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
  border-radius: 50%;
  overflow: hidden;
  // background-color: #FFFFFF;
}

</style>

<style lang="scss" scoped>
@import '@/static/css/templatePage/custom_nav_bar.scss';

.template-music {
}


.add-grain {
  position: fixed;

  bottom: 200rpx;
  right: 50rpx;
  font-size: 80rpx;

  z-index: 999;

}

/* 自定义导航栏内容 start */
.custom-nav {
  height: 100%;

  &__back {
    margin: auto 5rpx;
    font-size: 40rpx;
    margin-right: 10rpx;
    margin-left: 30rpx;
    flex-basis: 5%;
  }

  &__search {
    flex-basis: 60%;
    width: 100%;
    height: 100%;

    &__box {
      width: 100%;
      height: 70%;
      padding: 10rpx 0;
      margin: 0 30rpx;
      border-radius: 60rpx 60rpx 0 60rpx;
      font-size: 24rpx;
      background-color: rgba(255, 255, 255, 0.2);
    }

    &__icon {
      padding-right: 10rpx;
      margin-left: 20rpx;
      font-size: 30rpx;
    }

    &__text {
    }
  }
}

/* 自定义导航栏内容 end */

/* 图标容器12 start */
.tn-three {
  position: absolute;
  top: 50%;
  right: 50%;
  bottom: 50%;
  left: 50%;
  transform: translate(-38rpx, -16rpx) rotateX(30deg) rotateY(20deg) rotateZ(-30deg);
  text-shadow: -1rpx 2rpx 0 #f0f0f0, -2rpx 4rpx 0 #f0f0f0, -10rpx 20rpx 30rpx rgba(0, 0, 0, 0.2);
}

.icon12 {
  &__item {
    width: 30%;
    background-color: #FFFFFF;
    border-radius: 10rpx;
    padding: 30rpx;
    margin: 20rpx 10rpx;
    transform: scale(1);
    transition: transform 0.3s linear;
    transform-origin: center center;

    &--icon {
      width: 100rpx;
      height: 100rpx;
      font-size: 60rpx;
      border-radius: 50%;
      margin-bottom: 18rpx;
      position: relative;
      z-index: 1;

      &::after {
        content: " ";
        position: absolute;
        z-index: -1;
        width: 100%;
        height: 100%;
        left: 0;
        bottom: 0;
        border-radius: inherit;
        opacity: 1;
        transform: scale(1, 1);
        background-size: 100% 100%;
        background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/icon_bg.png);


      }
    }
  }
}

/* 文章内容 start*/
.tn-blogger-content {
  &__wrap {
    box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.12);
    border-radius: 20rpx;
    margin: 15rpx;
  }

  &__info {
    &__btn {
      margin-right: -12rpx;
      opacity: 0.5;
    }
  }

  &__label {
    &__item {
      line-height: 45rpx;
      padding: 0 20rpx;
      margin: 5rpx 18rpx 0 0;

      &--prefix {
        color: #82B2FF;
        padding-right: 10rpx;
      }
    }

    &__desc {
      line-height: 35rpx;
    }
  }

  &__main-image {
    border-radius: 16rpx 16rpx 0 0;

    &--1 {
      max-width: 690rpx;
      min-width: 690rpx;
      max-height: 400rpx;
      min-height: 400rpx;
    }

    &--2 {
      max-width: 260rpx;
      max-height: 260rpx;
    }

    &--3 {
      height: 212rpx;
      width: 100%;
    }
  }

  &__count-icon {
    font-size: 30rpx;
    padding-right: 5rpx;
  }
}

.image-music {
  padding: 150rpx 0rpx;
  font-size: 16rpx;
  font-weight: 300;
  position: relative;
}

.image-pic {
  background-size: cover;
  background-repeat: no-repeat;
  // background-attachment:fixed;
  background-position: top;
  border-radius: 20rpx 20rpx 0 0;
}

/* 文章内容 end*/

/* 底部tabbar start*/
.footerfixed {
  position: fixed;
  width: 100%;
  bottom: 0;
  z-index: 999;
  background-color: #FFFFFF;
  box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
}

.tabbar {
  display: flex;
  align-items: center;
  min-height: 110rpx;
  justify-content: space-between;
  padding: 0;
  height: calc(110rpx + env(safe-area-inset-bottom) / 2);
  padding-bottom: calc(env(safe-area-inset-bottom) / 2);
}

.tabbar .action {
  font-size: 22rpx;
  position: relative;
  flex: 1;
  text-align: center;
  padding: 0;
  display: block;
  height: auto;
  line-height: 1;
  margin: 0;
  overflow: initial;
}

.tabbar .action .bar-icon {
  width: 100rpx;
  position: relative;
  display: block;
  height: auto;
  margin: 0 auto 10rpx;
  text-align: center;
  font-size: 42rpx;
}

.tabbar .action .bar-icon image {
  width: 50rpx;
  height: 50rpx;
  display: inline-block;
}

/* 底部标签栏动画 */
.navbar__item .bar-text {
  font-variant: small-caps;
  margin: 0;
  padding: 0;
  display: inline-flex;
  text-align: center;
  justify-content: center;
  align-items: center;
  white-space: nowrap;
  position: relative;
  width: 50rpx;
  height: 50rpx;
  background-size: cover;
  background-position: center;
  vertical-align: middle;
  background-color: currentColor;
  border-radius: 50%;
  transform: scale(0.8);
  opacity: 0;
  transition: all 0.55s cubic-bezier(0.71, 0.03, 0.23, 0.95);
}

.navbar__item.-blue {
  color: #06b8ff;
}

.navbar__item.-orange {
  color: #f2704d;
}

.navbar__item.-yellow {
  color: #f8cd4b;
}

.navbar__item.-purple {
  color: #8444d6;
}

.bar-text.-blue {
  color: #06b8ff;
}

.bar-text.-orange {
  color: #f2704d;
}

.bar-text.-yellow {
  color: #f8cd4b;
}

.bar-text.-purple {
  color: #8444d6;
}

.navbar__item:active .bar-text {
  transform: translateY(-74rpx) scale(1.4);
  opacity: 1;
  box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.1),
  -1px -1px 5px rgba(255, 255, 255, 1);
}

.navbar__item:hover::before {
  opacity: 1;
}

.navbar__item:hover::after {
  opacity: 0.4;
}

.navbar__item:hover .navbar__icon {
  transform: translateY(-42rpx) scale(1);
  color: #fff;
  transition-delay: 0.1s, 0.1s;
}

.navbar__icon {
  bottom: -26rpx;
  transition: all 0.5s cubic-bezier(0.71, 0.03, 0.23, 0.95);
  transition-delay: 0.1s;
  display: inline-block;
  position: relative;
  z-index: 2;
}
</style>
